# 集合的创建1
s = set()
print(s, type(s))
s = {1, 2, 3, 4, 1}
print(s, type(s))
arr = [1, 2, 3, 4, 2, 3, 5]
s = set(arr)  # list --> set
print(s)
tuple1 = (1, 2, 3, 1)  # tuple --> set
s = set(tuple1)
print(s)
str1 = '1231234'
s = set(str1)  # str --> set
print(s)  # {'2', '1', '4', '3'}
# in
print('1' in s)  # True
d = {1: 'a', 2: 'b'}
s = set(d)  # dict字典 --> set 只保留键
print(s)  # {1, 2}
# del s
# len
print(len(s))
print(min({2, 3, 4, 1}))
# 集合的遍历
for i in s:
    print(i)
print(s)

# 集合的常用方法
s.remove(1)
print(s)
s.update({3, 4, 5, 6, 6})  # 无则添加
print(s)
s.add(99)
s.add('sd')
print(s)

# 交集和并集
s2 = {5, 6, 34, 21}
print(s & s2)  # 交集
print(s | s2)  # 并集

# 列表去重
score = [80, 70, 60, 80, 70, 60, 40]
s = set(score)
print(s)
d = {}
# 统计各个分数都有几个学生
for i in s:
    t = score.count(i)
    d[i] = t
for k, v in d.items():
    print('得分为%d的学生有%d个人' % (k, v))
